﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using zakalib.Tool;

namespace zakalib
{
    public static class Zaka
    {
        /// <summary>
        /// 测试接收数字
        /// </summary>
        /// <param name="text"></param>
        public static void TestReceiveInt(int text)
        {
            NativeZaka.test_receive_int(text);
        }

        /// <summary>
        /// 测试返回数字
        /// </summary>
        /// <returns></returns>
        public static int TestReturnInt()
        {
            int result = NativeZaka.test_return_int();
            return result;
        }

        /// <summary>
        /// 测试接收字符串
        /// </summary>
        /// <param name="content"></param>
        public static void TestReceiveString(string content)
        {
            //NativeZakka.test_receive_string(Marshal.StringToCoTaskMemUTF8(content));
            NativeZaka.test_receive_string(content);
        }

        /// <summary>
        /// 测试返回字符串
        /// </summary>
        /// <returns></returns>
        public static string TestReturnString()
        {
            IntPtr intPtr = NativeZaka.test_return_string();
            string result = Marshal.PtrToStringUTF8(intPtr);
            return result;
        }

        /// <summary>
        /// 测试接收结构体
        /// </summary>
        /// <param name="content"></param>
        public static void TestReceiveStruct(test_struct content)
        {
            //test_struct m = new test_struct();
            //m.user_age = content.user_age;
            //m.user_name = Marshal.StringToCoTaskMemUTF8(content.user_name);
            string json = content.ObjectToJson();
            NativeZaka.test_receive_struct(json);
        }

        #region 写日志

        #region 调试日志
        /// <summary>
        /// 调试日志
        /// </summary>
        /// <param name="content">日志内容</param>
        public static void Debug(string content)
        {
            NativeZaka.debug(content);
        }
        #endregion

        #region 信息日志
        /// <summary>
        /// 信息日志
        /// </summary>
        /// <param name="content">日志内容</param>
        public static void Info(string content)
        {
            NativeZaka.info(content);
        }
        #endregion

        #region 错误日志
        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="content">日志内容</param>
        public static void Error(string content)
        {
            NativeZaka.error(content);
        }
        #endregion

        #region 成功日志
        /// <summary>
        /// 成功日志
        /// </summary>
        /// <param name="content">日志内容</param>
        public static void Success(string content)
        {
            NativeZaka.success(content);
        }
        #endregion

        #region 异常日志
        /// <summary>
        /// 异常日志
        /// </summary>
        /// <param name="ex">异常内容</param>
        public static void Exception(Exception ex)
        {
            string content = ex.Message + Environment.NewLine + ex.StackTrace;
            NativeZaka.exception(content);
        }
        #endregion

        #region 自定义文件夹日志
        /// <summary>
        /// 自定义文件夹日志
        /// </summary>
        /// <param name="folder">文件夹名称</param>
        /// <param name="content">内容</param>
        public static void Custom(string folder, string content)
        {
            NativeZaka.custom(folder, content);
        }  
        #endregion

        #endregion

        public static string GetHtml(string url)
        {
            IntPtr urlPtr = Marshal.StringToCoTaskMemUTF8(url);
            IntPtr intPtr = NativeZaka.get_html(urlPtr);
            string result = Marshal.PtrToStringUTF8(intPtr);
            return result;
        }
    }

    public struct test_struct
    {
        public int user_age { get; set; }
        public string user_name { get; set; }
    }
}
